/**
 * 测试queue
 **/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <errno.h>
#include "../src/config.h"
#include "../src/queue.h"

int main(int argc, char* argv[])
{
    loadConfig("../conf/simq.conf");
    queue *q = queueCreate("sphinx");

    printf("------------------\n");
    printf(" short\n");
    printf("------------------\n");
    queueIn(q, "luyamin");
    printf(queueOut(q));
    printf("\n");
    queueIn(q, "1111");
    queueIn(q, "2222");
    queueIn(q, "3333333333333333333");
    printf(queueOut(q));
    printf("\n");
    printf(queueOut(q));
    printf("\n");
    printf(queueOut(q));
    printf("\n");
    printf(queueOut(q));
    printf("\n");

    printf("------------------\n");
    printf(" long\n");
    printf("------------------\n");

    int i = 0;
    char str[32];
    for (i = 0; i < 5000; i++) {
        sprintf(str, "number:%d", i);
        queueIn(q, str);
    }

    i = 0;
    char *out;
    while((out = queueOut(q)) != NULL) {
        printf("%s\n", out);
        i++;
        if (i > 4500) break;
    }

    printf("------------------\n");
    printf(" dump...\n");
    printf("------------------\n");
    queueDump(q);

    printf("------------------\n");
    printf(" restore...\n");
    printf("------------------\n");
    queueRestore(q);

    while((out = queueOut(q)) != NULL) {
        printf("%s\n", out);
    }

    queueFree(q);
    freeConfig();
    return 0;
}
